Skip to content

Allows Mistral byok to be used for Codestral#4000

Open
chrarnoldus wants to merge 3 commits into
mainfrom
christiaan/allow-codestral-mistral
Open

Allows Mistral byok to be used for Codestral#4000
chrarnoldus wants to merge 3 commits into
mainfrom
christiaan/allow-codestral-mistral

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

No description provided.

@chrarnoldus chrarnoldus self-assigned this Jun 12, 2026

const byokProviderKey = fimProvider === 'mistral' ? 'codestral' : 'inception';
const byokProviderKeys: UserByokProviderId[] =
fimProvider === 'mistral' ? ['codestral', 'mistral'] : ['inception'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: BYOK key priority not honoured — DB orderBy(created_at) overrides the ['codestral', 'mistral'] intent

getBYOKforUser/getBYOKforOrganization query with inArray(byok_api_keys.provider_id, providerIds) and orderBy(byok_api_keys.created_at). SQL's IN (…) clause does not preserve the input array order, so when a user has both a codestral key and a mistral key the DB returns them oldest-first.

userByok?.at(0) (line 237) then picks the oldest key regardless of which provider it is. If the mistral key was created before the codestral key, the codestral key is silently ignored and the user's Mistral La Plateforme key is used with api.mistral.ai — the correct endpoint for that key type, but the codestral key preference is lost.

To honour the priority ordering, consider re-sorting the returned entries client-side by their position in byokProviderKeys before calling .at(0):

const sorted = userByok?.slice().sort(
  (a, b) => byokProviderKeys.indexOf(a.providerId) - byokProviderKeys.indexOf(b.providerId)
);
const userByokEntry = sorted?.at(0);

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Comment thread apps/web/src/lib/ai-gateway/byok/index.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

All previously flagged issues have been resolved; the FIM route now correctly honours the ['codestral', 'mistral'] priority ordering when selecting a user BYOK key.

Previously Resolved Issues
File Issue Status
apps/web/src/app/api/fim/completions/route.ts BYOK key priority not honoured — userByok?.at(0) picked oldest key by DB insertion order ✅ Fixed: now iterates byokProviderKeys in priority order and finds first match
apps/web/src/lib/ai-gateway/byok/index.ts Array.prototype.splice → prefer unshift ✅ Fixed in earlier commit
Files Reviewed (4 files)
  • apps/web/src/app/api/fim/completions/route.ts — WARNING resolved
  • apps/web/src/lib/ai-gateway/byok/index.ts — no issues
  • apps/web/src/components/organizations/byok/BYOKKeysManager.tsx — no issues
  • apps/web/src/routers/byok-router.ts — no issues

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit 9ab1e0d)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 9ab1e0d)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The ['codestral', 'mistral'] priority ordering in the FIM route is still silently defeated by the DB query's orderBy(created_at), meaning a user with both keys may not get the expected key-to-endpoint routing.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/api/fim/completions/route.ts 158 BYOK key priority ordering ['codestral', 'mistral'] not honoured — DB returns rows by created_at, so userByok?.at(0) picks the oldest key, not the preferred codestral key
Previously Resolved Issues
File Issue Status
apps/web/src/lib/ai-gateway/byok/index.ts Array.prototype.splice → prefer unshift ✅ Fixed in latest commit
Files Reviewed (4 files)
  • apps/web/src/app/api/fim/completions/route.ts — 1 issue (WARNING, unchanged from previous review)
  • apps/web/src/lib/ai-gateway/byok/index.ts — suggestion resolved (spliceunshift)
  • apps/web/src/components/organizations/byok/BYOKKeysManager.tsx — no issues
  • apps/web/src/routers/byok-router.ts — no issues

Fix these issues in Kilo Cloud

Previous review (commit 34536a8)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The ['codestral', 'mistral'] priority ordering in the FIM route is silently defeated by the DB query's orderBy(created_at), meaning a user with both keys may not get the expected key-to-endpoint routing.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/api/fim/completions/route.ts 158 BYOK key priority ordering ['codestral', 'mistral'] not honoured — DB returns rows by created_at, so userByok?.at(0) picks the oldest key, not the preferred codestral key

SUGGESTION

File Line Issue
apps/web/src/lib/ai-gateway/byok/index.ts 32 providers.splice(0, 0, 'codestral') — unconventional; prefer providers.unshift('codestral') or ['codestral', ...providers]
Files Reviewed (4 files)
  • apps/web/src/app/api/fim/completions/route.ts — 1 issue
  • apps/web/src/lib/ai-gateway/byok/index.ts — 1 issue
  • apps/web/src/components/organizations/byok/BYOKKeysManager.tsx — no issues (rename of codestral entry to Legacy Codestral-only key and removal of (other models) suffix from mistral label)
  • apps/web/src/routers/byok-router.ts — no issues (removal of Codestral model filter from fetchSupportedModels so Codestral models now appear in the mistral provider list)

Fix these issues in Kilo Cloud


Reviewed by claude-4.6-sonnet-20260217 · 278,093 tokens

Review guidance: REVIEW.md from base branch main

Comment thread apps/web/src/lib/ai-gateway/byok/index.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant